package com.sigetdriver.view.popup;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.sigetdriver.R;
import com.sigetdriver.ServicioWorkingSet;
import com.sigetdriver.controller.ServicioController;
import com.sigetdriver.view.activity.VoucherActivity;

public class GuardarVoucherCreditoPopup {
	
	private Context context;
	public Dialog dialog;
	private EditText edtCodigo;
	private Button btnGrabar;
		
	public void dialog(Context _context, final String codigo) {
		
		context = _context;
		dialog = new Dialog(_context);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.popup_codigo);
		dialog.setCanceledOnTouchOutside(false);
		dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);	
		
		edtCodigo = (EditText) dialog.findViewById(R.id.edtCodigo);
		
		btnGrabar = (Button) dialog.findViewById(R.id.btnGrabar);
		btnGrabar.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (edtCodigo.getText().toString().equals(codigo)) {				
					ServicioController.getInstance().actualizarServicio(ServicioWorkingSet.servicio);
					Toast.makeText(context, "Voucher guardado correctamente", Toast.LENGTH_SHORT).show();
					((VoucherActivity) context).finish();
					dialog.dismiss();
				} else {
					Toast.makeText(context, "Codigo de voucher incorrecto", Toast.LENGTH_SHORT).show();
				}
			}
		});
		dialog.show();		
		
	}
	
}
